# -*- coding: UTF-8 -*-
"""
聊天命令 [普通指令]
By AnpyD
"""


# 设置PATH
import bs
import sys
sys.path.append(bs.getEnvironment()['systemScriptsDirectory'] + "/anm")

# 导入模块
import bsInternal
import json
import account_system
from game_stats import DATA_PATH


class chatOptions(object):
    def __init__(self):
        pass

    def get_account_id(self, clientID):
        for i in bsInternal._getForegroundHostActivity().players:
            if i.getInputDevice().getClientID() == clientID:
                ID = i.get_account_id()

        return ID

    def get_account_information(self, account_id):
        account_information_data = account_system.get_data()
        try:
            _file = open(DATA_PATH + "/player_stats.json")
            stats_data = json.loads(_file.read())
            if account_id not in stats_data or account_id not in account_information_data:
                account_information_data = account_system.get_data()
                tickets = account_information_data[account_id]["tickets"]
                rank = stats_data[account_id]["rank"]
                score = stats_data[account_id]["scores"]
                information = "现有资产: " + str(tickets) + " | 玩家等级: " + str(account_system.get_level(account_id)) + "\n赛季排名: " + str(rank) + " | 赛季得分: " + str(score)

            else:
                information = "抱歉，目前无法获取你的账户资料！请游玩2局以上再试！"
        except:
            information = "抱歉，目前无法获取你的账户资料！请游玩2局以上再试！"
            
        return information

    def opt(self,clientID,msg):
        m = msg.split(' ')[0]
        a = msg.split(' ', 1)[1:]
        activity = bsInternal._getForegroundHostActivity()
        with bs.Context(activity):
            if m == '/list':
                bsInternal._chatMessage("============玩家ID列表============")
                for s in bsInternal._getForegroundHostSession().players:
                    bsInternal._chatMessage(s.getName() +"  ID = "+ str(bsInternal._getForegroundHostSession().players.index(s)))
            elif m in ['/me', '/我自己']:
                pass

            else:
                bs.screenMessage('抱歉！没有此聊天命令！', clients = [clientID], transient=True, color=(1, 0, 0))
                                
        
c = chatOptions()

def cmd(msg, clientID):
    if bsInternal._getForegroundHostActivity() is not None:
        c.opt(clientID, msg)

bs.realTimer(5000, bs.Call(bsInternal._setPartyIconAlwaysVisible, True))